/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.client.db.tasks;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import pl.cezary.butler.walili.client.DownloadTask;
import pl.cezary.butler.walili.client.DownloadTaskStatus;
import pl.cezary.butler.walili.server.db.tasks.UpdateTask;

/**
 *
 * @author Czarek
 */
public class UpdateDownloadTask extends UpdateTask {

    private static final Logger log = Logger.getLogger(UpdateDownloadTask.class.getName());
    private final String url;
    private final DownloadTaskStatus status;

    public UpdateDownloadTask(DownloadTask task) {
        url = task.getUrl().toString();
        status = task.getStatus();
    }

    @Override
    public void execute() throws SQLException {
        if (getJdbcTemplate().update("update filesToDownload set status=? where url=?", status.ordinal(), url) != 0) {
            if (log.isLoggable(Level.FINE)) {
                log.log(Level.FINE, "Download task {0}, has changed status to {1}", new Object[]{url, status});
            }
        } else {
            log.log(Level.WARNING, "Download task {0}, hasn't been changed status to {1}", new Object[]{url, status});
        }

    }
}
